package com.sgb.trip.view.activity;

import android.text.TextUtils;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;

import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.fondesa.recyclerviewdivider.DividerDecoration;
import com.sgb.link.entity.EventConstant;
import com.sgb.link.entity.MainEvent;
import com.sgb.link.entity.trip.FlightSearchEntity;
import com.sgb.link.router.PathTrip;
import com.sgb.trip.R;
import com.sgb.trip.databinding.TripActivityCheckOrderBinding;
import com.sgb.trip.entity.FlightInfoEntity;
import com.sgb.trip.entity.InsureServiceEntity;
import com.sgb.trip.entity.PassengerInfoEntity;
import com.sgb.trip.view.adapter.InsureServiceAdapter;
import com.sgb.trip.view.adapter.PassengerChosenAdapter;
import com.sgb.trip.view.adapter.PassengerInfoChosenAdapter;
import com.sgb.trip.view.widget.FlightChosenDetailPopWindow;
import com.sgb.trip.view.widget.FlightOrderDetailPopWindow;
import com.sgb.trip.viewmodel.FlightCheckOrderModel;
import com.swgk.core.base.model.entity.RouterKey;
import com.swgk.core.common.base.BaseActivity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.ClickUtils;
import com.swgk.core.util.DateUtils;
import com.swgk.core.util.MToast;
import com.swgk.core.util.NumberUtil;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * Time:2021/10/9
 * Author:黄淋
 * Description:填写订单页 选择乘机人
 */
@Route(path = PathTrip.FlightCheckOrderActivity)
public class FlightCheckOrderActivity extends BaseActivity<FlightCheckOrderModel, TripActivityCheckOrderBinding> {
    PassengerChosenAdapter mAdapter;
    PassengerInfoChosenAdapter mAdapterInfo;
    InsureServiceAdapter insureServiceAdapter;

    FlightChosenDetailPopWindow mPopWindow;
    FlightOrderDetailPopWindow detailPopWindow;

    @Autowired(name = RouterKey.DATA, desc = "航班搜索内容")
    FlightSearchEntity mEntitySearch;

    @Autowired(name = RouterKey.DATA1, desc = "选择的去程航班信息")
    FlightInfoEntity mEntityTo;

    @Autowired(name = RouterKey.DATA2, desc = "返程航班信息")
    FlightInfoEntity mEntityBack;

    @Autowired(name = RouterKey.INT, desc = "去程选择的仓位")
    int positionTo;

    @Autowired(name = "INT2", desc = "返程选择的仓位")
    int positionBack;

    List<PassengerInfoEntity> mAllPassenger;//全部的乘客列表
    ArrayList<PassengerInfoEntity> mChosenPassenger;//选中的乘客列表

    private double ticketPrice;//票面总价
    private double adultTax;//机建费
    private double adultFuel;//燃油税
    private double insureFee;//保险费

    private Map<String, Object> map;

    @Override
    protected int layoutId() {
        return R.layout.trip_activity_check_order;
    }

    @Override
    protected void createViewModel() {
        mViewModel = new ViewModelProvider(this).get(FlightCheckOrderModel.class);

    }

    @Override
    protected void init() {
        ARouter.getInstance().inject(this);
        initAdapter();
        initWindow();
        mBinding.tvCheckFlightDetail.setOnClickListener(this);
        mBinding.tvCheckDetail.setOnClickListener(this);
        mBinding.tvCheckDetail.setVisibility(View.GONE);
        mBinding.tvUploadOrder.setOnClickListener(this);
        mBinding.ivBack.setOnClickListener(view -> finish());
        mAllPassenger = new ArrayList<>();
        mChosenPassenger = new ArrayList<>();
        map = new HashMap<>();

        setFlightInfo();

        mViewModel.getPassengersList("");
        mViewModel.ldPassengerData.observe(this, list -> {
            mAllPassenger.clear();
            mChosenPassenger.clear();
            mAdapterInfo.setDatas(new ArrayList<>());
            mAllPassenger.addAll(list);
            mAdapter.setDatas(new ArrayList<>());
            if (list.size() > 0 && list.size() <= 5) {
                mAdapter.setDatas(list);
                PassengerInfoEntity entity = new PassengerInfoEntity();
                entity.setName("新增");
                mAdapter.addData(entity);
            } else if (list.size() > 5) {
                mAdapter.setDatas(list.subList(0, 5));
                PassengerInfoEntity entity = new PassengerInfoEntity();
                entity.setName("更多");
                mAdapter.addData(entity);
            } else {
                PassengerInfoEntity entity = new PassengerInfoEntity();
                entity.setName("新增");
                mAdapter.addData(entity);
            }
        });

        mViewModel.getInsureData(new HashMap<>());
        mViewModel.ldInsureData.observe(this, list -> insureServiceAdapter.setDatas(list));

        mViewModel.ldPostData.observe(this, data -> {
            if (!TextUtils.isEmpty(data)) {
                ARouter.getInstance().build(PathTrip.FlightOrdersSelfActivity).navigation();
                EventBus.getDefault().post(MainEvent.make().setMessageTag(EventConstant.EVENT_TRIP_RE_CHOOSE_TO));
                finish();
            }
        });
    }

    /**
     * 加载航班信息
     */
    private void setFlightInfo() {
        if (mEntitySearch != null) {
            mBinding.tvStartCity.setText(mEntitySearch.getStartCity());
            mBinding.tvArriveCity.setText(mEntitySearch.getArriveCity());
            mBinding.tvCityTo.setText(mEntitySearch.getStartCity() + " → " + mEntitySearch.getArriveCity());
            if (mEntityTo != null) {
                String builder = DateUtils.formatDate(mEntitySearch.getStartDateStamp(), "MM月dd日") +
                        " " +
                        "星期" + mEntitySearch.getStartWeek() +
                        " " + mEntityTo.getFromDateTime() + " " + mEntityTo.getTickets().get(positionTo).getCabinName();
                mBinding.tvTimeTo.setText(builder);
            }
            if (mEntitySearch.isSingle()) {
                mBinding.ivArrowDirection.setImageResource(R.mipmap.icon_arrow_right);
                mBinding.tvTo.setVisibility(View.GONE);
                mBinding.tvBack.setVisibility(View.GONE);
                mBinding.tvCityBack.setVisibility(View.GONE);
                mBinding.tvTimeBack.setVisibility(View.GONE);
                if (mEntityTo != null) {
                    ticketPrice = mEntityTo.getTickets().get(positionTo).getCabinPrice().getAdultFarePrice();
                    adultTax = mEntityTo.getAdultTax();
                    adultFuel = mEntityTo.getAdultFuel();
                    mBinding.tvTicketPrice.setText("¥" + NumberUtil.trim0(ticketPrice));
                    mBinding.tvAirportTax.setText("¥" + NumberUtil.trim0(adultTax));
                    mBinding.tvFuelTax.setText("¥" + NumberUtil.trim0(adultFuel));
                }

            } else {
                mBinding.ivArrowDirection.setImageResource(R.mipmap.icon_arrow_return);
                mBinding.tvTo.setVisibility(View.VISIBLE);
                mBinding.tvTo.setVisibility(View.VISIBLE);
                mBinding.tvBack.setVisibility(View.VISIBLE);
                mBinding.tvCityBack.setVisibility(View.VISIBLE);
                mBinding.tvTimeBack.setVisibility(View.VISIBLE);

                mBinding.tvCityBack.setText(mEntitySearch.getArriveCity() + " → " + mEntitySearch.getStartCity());
                if (mEntityBack != null) {
                    String builder = DateUtils.formatDate(mEntitySearch.getReturnDateStamp(), "MM月dd日") +
                            " " +
                            "星期" + mEntitySearch.getBackWeek() +
                            " " + mEntityBack.getFromDateTime() + " " + mEntityBack.getTickets().get(positionBack).getCabinName();
                    mBinding.tvTimeBack.setText(builder);

                    if (mEntityTo != null) {
                        ticketPrice = mEntityTo.getTickets().get(positionTo).getCabinPrice().getAdultFarePrice() +
                                mEntityBack.getTickets().get(positionBack).getCabinPrice().getAdultFarePrice();
                        adultTax = mEntityTo.getAdultTax() + mEntityBack.getAdultTax();
                        adultFuel = mEntityTo.getAdultFuel() + mEntityBack.getAdultFuel();
                        mBinding.tvTicketPrice.setText("¥" + NumberUtil.trim0(ticketPrice));
                        mBinding.tvAirportTax.setText("¥" + NumberUtil.trim0(adultTax));
                        mBinding.tvFuelTax.setText("¥" + NumberUtil.trim0(adultFuel));

                    }
                }
            }
        }
    }

    /**
     * 初始化适配器
     */
    private void initAdapter() {
        mBinding.rvPassengers.setLayoutManager(new GridLayoutManager(this, 3));
        mBinding.rvPassengers.setLoadingMoreEnabled(false);
        mBinding.rvPassengers.setPullRefreshEnabled(false);

        mAdapter = new PassengerChosenAdapter(this, null);
        mAdapter.setMultiSelect(true);

        mAdapter.setOnItemClick2(new BaseRecycleAdapter.OnItemClick2<PassengerInfoEntity>() {
            @Override
            public void onItemClick(PassengerInfoEntity passengerInfoEntity, int position, ItemViewHolder view) {
                if (passengerInfoEntity.getName().equals("新增")) {
                    ARouter.getInstance().build(PathTrip.FlightAddPassengerActivity).withBoolean(RouterKey.BOOLEAN, false).navigation();
                } else if (passengerInfoEntity.getName().equals("更多")) {
                    ARouter.getInstance().build(PathTrip.FlightChoosePassengerActivity).withParcelableArrayList(RouterKey.DATA, mChosenPassenger).navigation();
                } else {
                    passengerInfoEntity.setSelected(!view.getItem().isSelected());

                    for (int a = 0; a < mAllPassenger.size(); a++) {
                        if (passengerInfoEntity.getIdCard().equals(mAllPassenger.get(a).getIdCard())) {
                            mAllPassenger.get(a).setSelected(passengerInfoEntity.isSelected());
                        }
                    }

                    mChosenPassenger.clear();
                    for (int a = 0; a < mAllPassenger.size(); a++) {
                        if (mAllPassenger.get(a).isSelected()) {
                            mChosenPassenger.add(mAllPassenger.get(a));
                        }
                    }
                    mAdapterInfo.setDatas(mChosenPassenger);
                    setAllAccount();
                }
            }
        });
        mBinding.rvPassengers.setAdapter(mAdapter);


        mBinding.rvPassengersInfo.setLayoutManager(new LinearLayoutManager(this));
        DividerDecoration.builder(this)
                .colorRes(R.color.color_EDEDED)
                .size(1, TypedValue.COMPLEX_UNIT_PX)
                .build()
                .addTo(mBinding.rvPassengersInfo);
        mAdapterInfo = new PassengerInfoChosenAdapter(this, null);
        mAdapterInfo.setOnClickItem(new PassengerInfoChosenAdapter.OnClickItem() {
            @Override
            public void onEdit(PassengerInfoEntity entity) {
                ARouter.getInstance().build(PathTrip.FlightAddPassengerActivity).withBoolean(RouterKey.BOOLEAN, true).withSerializable(RouterKey.DATA, entity).navigation();
            }

            @Override
            public void onDelete(PassengerInfoEntity entity) {
                entity.setSelected(false);
                for (int a = 0; a < mAllPassenger.size(); a++) {
                    if (entity.getIdCard().equals(mAllPassenger.get(a).getIdCard())) {
                        mAllPassenger.get(a).setSelected(entity.isSelected());
                    }
                }

                //设置选中的全部乘客数据
                mChosenPassenger.clear();
                for (int a = 0; a < mAllPassenger.size(); a++) {
                    if (mAllPassenger.get(a).isSelected()) {
                        mChosenPassenger.add(mAllPassenger.get(a));
                    }
                }
                mAdapterInfo.setDatas(mChosenPassenger);
                setAllAccount();

                //设置顶部部分乘客数据
                if (mAllPassenger != null && mAllPassenger.size() > 0) {
                    if (mAllPassenger.size() <= 5) {
                        mAdapter.setDatas(mAllPassenger);
                        PassengerInfoEntity entity1 = new PassengerInfoEntity();
                        entity1.setName("新增");
                        mAdapter.addData(entity1);
                    } else {
                        mAdapter.setDatas(mAllPassenger.subList(0, 5));
                        PassengerInfoEntity entity1 = new PassengerInfoEntity();
                        entity1.setName("更多");
                        mAdapter.addData(entity1);
                    }
                }
            }
        });
        mBinding.rvPassengersInfo.setAdapter(mAdapterInfo);

        mBinding.rvInsureService.setLayoutManager(new LinearLayoutManager(this));
        DividerDecoration.builder(this)
                .colorRes(R.color.color_EDEDED)
                .size(1, TypedValue.COMPLEX_UNIT_PX)
                .build()
                .addTo(mBinding.rvInsureService);
        insureServiceAdapter = new InsureServiceAdapter(this, null);
        insureServiceAdapter.setMultiSelect(true);
        mBinding.rvInsureService.setAdapter(insureServiceAdapter);
        insureServiceAdapter.setOnItemMultiClick(new BaseRecycleAdapter.OnItemMultiClick<InsureServiceEntity>() {
            @Override
            public void onItemMultiClick(List<InsureServiceEntity> insureServiceEntities, int position) {
                insureFee = 0;
                if (mChosenPassenger != null && mChosenPassenger.size() > 0) {
                    for (int i = 0; i < insureServiceEntities.size(); i++) {
                        insureFee += insureServiceEntities.get(i).getInsuranceFee();
                    }
                    if (!mEntitySearch.isSingle()) {
                        insureFee = insureFee * 2;
                    }
                    setAllAccount();
                } else {
                    for (int i = 0; i < insureServiceEntities.size(); i++) {
                        insureFee += insureServiceEntities.get(i).getInsuranceFee();
                    }
                    if (!mEntitySearch.isSingle()) {
                        insureFee = insureFee * 2;
                    }
                }
            }
        });

        mAdapter.setClickDelay(false);
        mAdapterInfo.setClickDelay(false);
        insureServiceAdapter.setClickDelay(false);
    }

    /**
     * 初始化航班详情弹窗
     */
    private void initWindow() {
        mPopWindow = new FlightChosenDetailPopWindow(this);
        mPopWindow.setEntitySearch(mEntitySearch);
        mPopWindow.setEntityTo(mEntityTo);
        mPopWindow.setEntityBack(mEntityBack);

        detailPopWindow = new FlightOrderDetailPopWindow(this);
        detailPopWindow.setEntitySearch(mEntitySearch);
        detailPopWindow.setEntityTo(mEntityTo);
        detailPopWindow.setEntityBack(mEntityBack);
        detailPopWindow.setPositionTo(positionTo);
        detailPopWindow.setPositionBack(positionBack);
    }

    /**
     * 计算总价
     */
    private void setAllAccount() {
        if (mChosenPassenger != null) {
            int passengerCount = mChosenPassenger.size();
            mBinding.tvCheckDetail.setVisibility(passengerCount == 0 ? View.GONE : View.VISIBLE);
            mBinding.tvAllPrice.setText("¥" + NumberUtil.formatTwoDigits(passengerCount * (ticketPrice + adultTax + adultFuel + insureFee)));
        }
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.tv_check_flight_detail) {//查看航班详情
            if (mPopWindow != null) {
                mPopWindow.showAtLocation(mBinding.llTitleView, Gravity.CENTER, 0, 0);
                mPopWindow.backgroundAlpha(0.5f);
                mPopWindow.setDataShow();
            }
        } else if (view.getId() == R.id.tv_check_detail) {//查看订单明细
            if (detailPopWindow != null && mChosenPassenger != null && mChosenPassenger.size() > 0) {
                detailPopWindow.setPassengerCount(mChosenPassenger.size());
                detailPopWindow.setInsureArrayList(insureServiceAdapter.getCheckDatas());
                detailPopWindow.showDownPopwindow(mBinding.clBottom, true);
                detailPopWindow.backgroundAlpha(0.5f);

                detailPopWindow.setAllCount(mChosenPassenger.size() * (ticketPrice + adultTax + adultFuel + insureFee));

                detailPopWindow.setDataShow();
            }
        } else if (view.getId() == R.id.tv_upload_order) {//提交订单
            if (mChosenPassenger == null || mChosenPassenger.size() == 0) {
                MToast.showToast(FlightCheckOrderActivity.this, "请选择乘机人！");
                return;
            }
            if (TextUtils.isEmpty(mBinding.itvInputName.getContent())) {
                MToast.showToast(FlightCheckOrderActivity.this, "请输入姓名！");
                return;
            }
            if (TextUtils.isEmpty(mBinding.contentEdtPhone.getText().toString())) {
                MToast.showToast(FlightCheckOrderActivity.this, "请输入联系电话");
                return;
            }
            if (mBinding.contentEdtPhone.getText().toString().trim().length() != 11 || !mBinding.contentEdtPhone.getText().toString().startsWith("1")) {
                MToast.showToast(FlightCheckOrderActivity.this, "请输入正确的联系电话！");
                return;
            }
            map.put("contactName", mBinding.itvInputName.getContent());
            map.put("contactMobile", mBinding.contentEdtPhone.getText().toString().trim());
            map.put("isSingleTicket", mEntitySearch.isSingle() ? 1 : 2);
            if (insureServiceAdapter.getCheckDatas() != null && insureServiceAdapter.getCheckDatas().size() > 0) {
                ArrayList<Integer> insure = new ArrayList<>();
                for (int i = 0; i < insureServiceAdapter.getCheckDatas().size(); i++) {
                    insure.add(insureServiceAdapter.getCheckDatas().get(i).getInsuranceType());
                }
                map.put("insuranceIds", insure);
            }

            ArrayList<String> passenger = new ArrayList<>();
            for (int i = 0; i < mChosenPassenger.size(); i++) {
                passenger.add(mChosenPassenger.get(i).getId());
            }
            map.put("passengersIds", passenger);

            ArrayList<FlightInfoEntity> flight = new ArrayList<>();
            if (mEntitySearch.isSingle()) {
                FlightInfoEntity entityTo = new FlightInfoEntity();
                entityTo.setTicketsType(1);
                entityTo.setTicketPrice(NumberUtil.trim0(mEntityTo.getTickets().get(positionTo).getCabinPrice().getAdultFarePrice()));
                entityTo.setAdultFuel(mEntityTo.getAdultFuel());
                entityTo.setAdultTax(mEntityTo.getAdultTax());
                entityTo.setAirlineCode(mEntityTo.getAirlineCode());
                entityTo.setCabinCode(mEntityTo.getTickets().get(positionTo).getCabinCode());
                entityTo.setCabinBookParms(mEntityTo.getTickets().get(positionTo).getCabinBookPara());
                entityTo.setCabinLevel(mEntityTo.getTickets().get(positionTo).getCabinLevel());
                entityTo.setCraftType(mEntityTo.getCraftType());
                entityTo.setFlightNo(mEntityTo.getFlightNo());
                entityTo.setFromAirportCode(mEntityTo.getFromAirportCode());
                entityTo.setFromCity(mEntitySearch.getStartCityNo());
                entityTo.setFromDateTime(mEntityTo.getFromDate() + " " + mEntityTo.getFromDateTime());
                entityTo.setFromTerminal(mEntityTo.getFromTerminal());
                entityTo.setShareFlight(mEntityTo.isShareFlight());
                entityTo.setRealFlightNo(mEntityTo.getRealFlightNo());
                entityTo.setToAirportCode(mEntityTo.getToAirportCode());
                entityTo.setToCity(mEntitySearch.getArriveCityNo());
                entityTo.setToDateTime(mEntityTo.getToDate() + " " + mEntityTo.getToDateTime());
                entityTo.setToTerminal(mEntityTo.getToTerminal());

                flight.add(entityTo);
            } else {
                FlightInfoEntity entityTo = new FlightInfoEntity();
                entityTo.setTicketsType(1);
                entityTo.setTicketPrice(NumberUtil.trim0(mEntityTo.getTickets().get(positionTo).getCabinPrice().getAdultFarePrice()));
                entityTo.setAdultFuel(mEntityTo.getAdultFuel());
                entityTo.setAdultTax(mEntityTo.getAdultTax());
                entityTo.setAirlineCode(mEntityTo.getAirlineCode());
                entityTo.setCabinCode(mEntityTo.getTickets().get(positionTo).getCabinCode());
                entityTo.setCabinBookParms(mEntityTo.getTickets().get(positionTo).getCabinBookPara());
                entityTo.setCabinLevel(mEntityTo.getTickets().get(positionTo).getCabinLevel());
                entityTo.setCraftType(mEntityTo.getCraftType());
                entityTo.setFlightNo(mEntityTo.getFlightNo());
                entityTo.setFromAirportCode(mEntityTo.getFromAirportCode());
                entityTo.setFromCity(mEntitySearch.getStartCityNo());
                entityTo.setFromDateTime(mEntityTo.getFromDate() + " " + mEntityTo.getFromDateTime());
                entityTo.setFromTerminal(mEntityTo.getFromTerminal());
                entityTo.setShareFlight(mEntityTo.isShareFlight());
                entityTo.setRealFlightNo(mEntityTo.getRealFlightNo());
                entityTo.setToAirportCode(mEntityTo.getToAirportCode());
                entityTo.setToCity(mEntitySearch.getArriveCityNo());
                entityTo.setToDateTime(mEntityTo.getToDate() + " " + mEntityTo.getToDateTime());
                entityTo.setToTerminal(mEntityTo.getToTerminal());
                flight.add(entityTo);

                FlightInfoEntity entityBack = new FlightInfoEntity();
                entityBack.setTicketsType(2);
                entityBack.setTicketPrice(NumberUtil.trim0(mEntityBack.getTickets().get(positionBack).getCabinPrice().getAdultFarePrice()));
                entityBack.setAdultFuel(mEntityBack.getAdultFuel());
                entityBack.setAdultTax(mEntityBack.getAdultTax());
                entityBack.setAirlineCode(mEntityBack.getAirlineCode());
                entityBack.setCabinCode(mEntityBack.getTickets().get(positionTo).getCabinCode());
                entityBack.setCabinBookParms(mEntityBack.getTickets().get(positionTo).getCabinBookPara());
                entityBack.setCabinLevel(mEntityBack.getTickets().get(positionTo).getCabinLevel());
                entityBack.setCraftType(mEntityBack.getCraftType());
                entityBack.setFlightNo(mEntityBack.getFlightNo());
                entityBack.setFromAirportCode(mEntityBack.getFromAirportCode());
                entityBack.setFromCity(mEntitySearch.getStartCityNo());
                entityBack.setFromDateTime(mEntityBack.getFromDate() + " " + mEntityBack.getFromDateTime());
                entityBack.setFromTerminal(mEntityBack.getFromTerminal());
                entityBack.setShareFlight(mEntityBack.isShareFlight());
                entityBack.setRealFlightNo(mEntityBack.getRealFlightNo());
                entityBack.setToAirportCode(mEntityBack.getToAirportCode());
                entityBack.setToCity(mEntitySearch.getArriveCityNo());
                entityBack.setToDateTime(mEntityBack.getToDate() + " " + mEntityBack.getToDateTime());
                entityBack.setToTerminal(mEntityBack.getToTerminal());
                flight.add(entityBack);
            }
            map.put("flights", flight);

            if (!ClickUtils.isDoubleClick2()) {
                DialogHelper.showProgressDialog(this, "加载中...").setCanceledOnTouchOutside(false);
                mViewModel.postOrder(map);
            }
        }

    }

    @Override
    public boolean isUseEventBus() {
        return true;
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEvent(MainEvent event) {
        if (event == null) return;
        if (event.getMessageTag() == EventConstant.EVENT_TRIP_CHOOSE_PASSENGER) {
            mAllPassenger = (List<PassengerInfoEntity>) event.getMessageData();
            if (mAllPassenger != null && mAllPassenger.size() > 0) {
                if (mAllPassenger.size() <= 5) {
                    mAdapter.setDatas(mAllPassenger);
                    PassengerInfoEntity entity = new PassengerInfoEntity();
                    entity.setName("新增");
                    mAdapter.addData(entity);
                } else {
                    mAdapter.setDatas(mAllPassenger.subList(0, 5));
                    PassengerInfoEntity entity = new PassengerInfoEntity();
                    entity.setName("更多");
                    mAdapter.addData(entity);
                }
            }
            mChosenPassenger.clear();
            for (int a = 0; a < mAllPassenger.size(); a++) {
                if (mAllPassenger.get(a).isSelected()) {
                    mChosenPassenger.add(mAllPassenger.get(a));
                }
            }
            mAdapterInfo.setDatas(mChosenPassenger);
            setAllAccount();
        } else if (event.getMessageTag() == EventConstant.EVENT_TRIP_EDIT_PASSENGER_REFRESH_ORDER) {
            mViewModel.getPassengersList("");
        }
    }
}
